// https://www.acwing.com/problem/content/106/

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    sort(arr.begin(), arr.end());
    int tmp = n / 2;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(arr[i] - arr[tmp]);
    }

    printf("%d\n", ans);
    return 0;
}